package com.fengba.nanzhi.utils;

import android.annotation.SuppressLint;
import android.app.Fragment;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.fengba.nanzhi.fengba.R;

import junit.framework.Test;

/**
 * Created by duan on 2018/4/13.
 */

public class DDImageTxtFragment extends Fragment {

    private String imgName;
    private String textName;
    private int pointX;
    private int pointY;
    private int width;
    private int height;

    public Button btn01;

    public myCallBack my;


    public DDImageTxtFragment(){
    }


    @SuppressLint("ValidFragment")
    public  DDImageTxtFragment(String imgName, String textName,int x,int y,int w,int h){
        this.imgName = imgName;
        this.textName = textName;
        this.pointX = x;
        this.pointY = y;
        this.width = w;
        this.height = h;

    }

    @Override
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState){

        /**
         * 屏幕的宽高
         */
        int screenWidth = Function.getScreenWidth(this.getActivity());
        int screenHeight = Function.getScreenHeight(this.getActivity());

        /**
         * 本类中layout的View
         */
        View view = inflater.inflate(R.layout.dd_imagetxt,container,false);
        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(0,0);
        params.leftMargin = Function.dip2px(getActivity(),pointX);
        params.topMargin = Function.dip2px(getActivity(),pointY);
        params.height = Function.dip2px(getActivity(),height);
        params.width = Function.dip2px(getActivity(),width);
        view.setLayoutParams(params);

        btn01 = (Button) view.findViewById(R.id.btn01);
        ImageView imgv = (ImageView)view.findViewById(R.id.image01);
        imgv.setImageResource(Function.getResourceId(imgName));

        TextView tv = (TextView)view.findViewById(R.id.txt01);
        tv.setText(textName);

        btn01.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                sendNotifyMessage("s");
            }
        });

        return view;
    }

    public void sendNotifyMessage(String msg){
        my.success();

    }


    public void setNotifyMessage(myCallBack myCallBack){
        my = myCallBack;
    }

    public interface myCallBack {
        void success();
    }


}
